/**
 * created by 小卷毛, 2021-06-12
 * Copyright (c) 2021, 416143467@qq.com All Rights Reserved.
 * #                   *********                            #
 * #                  ************                          #
 * #                  *************                         #
 * #                 **  ***********                        #
 * #                ***  ****** *****                       #
 * #                *** *******   ****                      #
 * #               ***  ********** ****                     #
 * #              ****  *********** ****                    #
 * #            *****   ***********  *****                  #
 * #           ******   *** ********   *****                #
 * #           *****   ***   ********   ******              #
 * #          ******   ***  ***********   ******            #
 * #         ******   **** **************  ******           #
 * #        *******  ********************* *******          #
 * #        *******  ******************************         #
 * #       *******  ****** ***************** *******        #
 * #       *******  ****** ****** *********   ******        #
 * #       *******    **  ******   ******     ******        #
 * #       *******        ******    *****     *****         #
 * #        ******        *****     *****     ****          #
 * #         *****        ****      *****     ***           #
 * #          *****       ***        ***      *             #
 * #            **       ****        ****                   #
 */
@file:Suppress("PrivatePropertyName")

package com.tim.library.third

import android.app.NotificationChannel
import android.app.NotificationManager
import android.content.Context
import android.os.Build
import com.heytap.msp.push.callback.ICallBackResultService
import com.tencent.qcloud.tim.tuiofflinepush.utils.TUIOfflinePushLog

/**
 * 描 述：
 * 作 者：小卷毛  2021-06-12 18:02
 * 修改描述：
 * 修 改 人：
 * 修改版本：
 */
class OPPOPushMessageService : ICallBackResultService {

    private val NOTIFICATION_ID = "IM_OPPO_SLG_NOTIFY_ID"
    private val NOTIFICATION_NAME = "IM_OPPO_SLG_NOTIFY_NAME"

    private val mTAG = this::class.java.simpleName

    override fun onRegister(responseCode: Int, registerID: String?) {
        TUIOfflinePushLog.i(mTAG, "onRegister responseCode: $responseCode registerID: $registerID")

        ThirdPushTokenManager.getInstance().thirdPushToken = registerID
        ThirdPushTokenManager.getInstance().setPushTokenToTIM()
    }

    override fun onUnRegister(responseCode: Int) {
        TUIOfflinePushLog.i(mTAG, "onUnRegister responseCode: $responseCode")
    }

    override fun onSetPushTime(responseCode: Int, s: String?) {
        TUIOfflinePushLog.i(mTAG, "onSetPushTime responseCode: $responseCode s: $s")
    }

    override fun onGetPushStatus(responseCode: Int, status: Int) {
        TUIOfflinePushLog.i(mTAG, "onGetPushStatus responseCode: $responseCode status: $status")
    }

    override fun onGetNotificationStatus(responseCode: Int, status: Int) {
        TUIOfflinePushLog.i(
            mTAG,
            "onGetNotificationStatus responseCode: $responseCode status: $status"
        )
    }

    override fun onError(responseCode: Int, s: String?) {
        TUIOfflinePushLog.i(mTAG, "onError code: $responseCode string: $s")
    }

    fun createNotificationChannel(context: Context) {
        // Create the NotificationChannel, but only on API 26+ because
        // the NotificationChannel class is new and not in the support library
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            val channel = NotificationChannel(
                NOTIFICATION_ID,
                NOTIFICATION_NAME,
                NotificationManager.IMPORTANCE_DEFAULT
            )
            // Register the channel with the system; you can't change the importance
            // or other notification behaviors after this
            val notificationManager = context.getSystemService(NotificationManager::class.java)
            notificationManager.createNotificationChannel(channel)
        }
    }

}